home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4432 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  55 lines

  1. Path: Austria.EU.net!usenet
  2. From: niederle@deas.co.at
  3. Newsgroups: comp.lang.c++
  4. Subject: Templates and Recursive Structures
  5. Date: 29 Jan 1996 11:49:49 GMT
  6. Organization: DEAS EDV-Loesungen GmbH, 1070 Wien
  7. Message-ID: <4eic8t$20g@news.Austria.EU.net>
  8. NNTP-Posting-Host: s16.vie2.austria.eu.net
  9. X-Newsreader: AIR News 3.X (SPRY, Inc.)
  10.  
  11. I want to define an array type of my own and use it to build tree-like
  12. structures:
  13.  
  14. struct T2;
  15.  
  16. struct T1
  17.  {
  18.  ARRAY <T2>
  19.  };
  20.  
  21. struct T2
  22.  {
  23.  ARRAY <T1>
  24.  };
  25.  
  26. The data structure defined would be absolutely sensefull because the leafes
  27. of the tree will contain empty arrays.
  28.  
  29. The problem is that within the ARRAY class I need the size of the base type
  30. to access the array's items.
  31.  
  32. e.g. try the following simple ARRAY class
  33. (the size is used implicitely in "buf[idx]"):
  34.  
  35. template <class BASE_TYPE>
  36. struct ARRAY
  37.  {
  38.  BASE_TYPE *buf;
  39.  
  40.  BASE_TYPE &operator [](int idx)
  41.   {
  42.    return buf[idx];
  43.   }
  44.  }
  45.  
  46. The compiler reports an error when creating the template member function
  47. operator [] for T1 because it does no know the size of T2 at this moment!
  48.  
  49. Is there a solution or is this a general leak in the specification of C++?
  50.  
  51. I tried the above examples with BORLAND C++ 4.5.
  52.  
  53. mfG Michael Niederle
  54.  
  55.